//================v1要点总结===============
/**
 * 1.
 * 2. 只有爬上一个台阶，才能选下一个，因此:
 *   n = 2时，min = Math.min(f1,f2)
 *   n = 3时， min = Math.min(f2,f1) = math.min(0+f2,0+ f1)
 *   n >= 3 时，min = Math.min(min_(n-1) + f(n-1),min_(n-2) + f(n-2) )
 *
 *
 *
 *
 */

/**
 * @param {number[]} cost
 * @return {number}
 */
var minCostClimbingStairs = function (cost) {
  let len = cost.length
  if (len === 2) {
    return Math.min(cost[0], cost[1])
  }
  let m0 = 0
  let m1 = 0
  let m
  for (let i = 2; i <= len; i++) {
    m = Math.min(m1 + cost[i - 1], m0 + cost[i - 2])
    m0 = m1
    m1 = m
  }
  return m
}

// output 6
console.log(minCostClimbingStairs([1, 100, 1, 1, 1, 100, 1, 1, 100, 1]))
